package org.service.car.helper;

import java.util.List;

import org.service.car.R;
import org.service.car.pojo.Revisao;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;


    /**
     * A simple adapter which maintains an ArrayList of photo resource Ids. 
     * Each photo is displayed as an image. This adapter supports clearing the
     * list of photos and adding a new photo.
     *
     */
    public class MyExpandableAdapter extends BaseExpandableListAdapter {
    	private Context context;
    	private List<Revisao> revisoes;
    	
		public  MyExpandableAdapter(Context context, List<Revisao> revisoes){
        	this.context = context.getApplicationContext();
        	this.revisoes = revisoes;
        }
        

		public Object getChild(int groupPosition, int childPosition) {
            return revisoes.get(groupPosition).getItens().get(childPosition);
        }

        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

        public int getChildrenCount(int groupPosition) {
            return revisoes.get(groupPosition).getItens().size();
        }

        public TextView getGenericView() {
            // Layout parameters for the ExpandableListView
            AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, 64);

            TextView textView = new TextView(context);
            textView.setLayoutParams(lp);
            /*// Center the text vertically
            textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);*/
            textView.setTextAppearance(context, R.style.text_view_group_style);
            // Set the text starting position
            textView.setPadding(60, 10, 0, 0);
            return textView;
        }
        
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                View convertView, ViewGroup parent) {
            TextView textView = getGenericView();
            textView.setText(getChild(groupPosition, childPosition).toString());
            return textView;
        }

        public Object getGroup(int groupPosition) {
            return revisoes.get(groupPosition);
        }

        public int getGroupCount() {
            return revisoes.size();
        }

        public long getGroupId(int groupPosition) {
            return groupPosition;
        }

        public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
                ViewGroup parent) {
            TextView textView = getGenericView();
            textView.setText(getGroup(groupPosition).toString());
            return textView;
        }

        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }

        public boolean hasStableIds() {
            return true;
        }
}
